import { Injectable } from '@angular/core';
import {
  Router, Resolve,
  RouterStateSnapshot,
  ActivatedRouteSnapshot
} from '@angular/router';
import { Observable, of } from 'rxjs';

type returnType = Promise<{ name: string }>

@Injectable({
  providedIn: 'root'
})
// export class AsyncResolver implements Resolve<boolean> {
export class AsyncResolver implements Resolve<returnType> {
  // resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
  //   return of(true);
  // }

  resolve(): returnType {
    return new Promise(function (resolve) {
      setTimeout(() => {
        resolve({ name: "张三" })
      }, 2000)
    })
  }
}
